package com.yootk.actuator;

import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;

/**
 * 自定义监控检查类
 */
@Component
public class MicroHealthIndicator implements HealthIndicator {

    @Override
    public Health health() {
        int errorCode = 100;    // 假设存在有一个错误编码
        if (errorCode != 0) {   // 触发返回错误的条件
            return Health.down().withDetail("MicroServiceErrorCode", errorCode)
                    .withException(new Exception("服务故障！")).build();     // 当前微服务不健康
        }
        return Health.up().build();     // 当前微服务健康
    }
}
